﻿using System;
using System.Collections.Generic;
namespace AStarFinder
{
    /*
     * 地图区块类型
     */
    enum TITLE_TYPE
    {
        TT_NONE = 0,    // 空
        TT_OBSTACLE,    // 障碍
        TT_OPEN,        // 打开列表
        TT_CLOSE,       // 关闭列表
    }

    /*
     * 地图管理 
     */
    class CTitleMap
    {
        enum MAPSIZE
        {
            MAPSIZE_X = 512,    
            MAPSIZE_Y = 512,
        }

        public CTitleMap()
        {
            m_lstTitle.AddRange(new int[m_nMaxX * m_nMaxY]);
        }

        public CTitleMap(int nX, int nY)
        {
            m_nMaxX = nX;
            m_nMaxY = nY;
            m_lstTitle.AddRange(new int[m_nMaxX * m_nMaxY]);
        }

        // x
        public int GetX() { return m_nMaxX; }

        // y
        public int GetY() { return m_nMaxY; }

        // 取得大小
        public int GetSize()
        {
            return (int)MAPSIZE.MAPSIZE_X * (int)MAPSIZE.MAPSIZE_Y;
        }

        // 设置区块
        public void SetTitle(int x, int y, TITLE_TYPE type)
        {
            if (x >= (int)MAPSIZE.MAPSIZE_X || y >= (int)MAPSIZE.MAPSIZE_Y)
            {
                return;
            }
            m_lstTitle[x + y * m_nMaxX] = (int)type;
        }

        // 取得区块
        public int GetTitle(int x, int y)
        {
            return m_lstTitle[x + y * m_nMaxX];
        }

        // 清空信息
        public void Clear()
        {
            for (int i = 0; i != m_lstTitle.Count; ++i)
            {
                if (m_lstTitle[i] == (int)TITLE_TYPE.TT_OPEN
                    || m_lstTitle[i] == (int)TITLE_TYPE.TT_CLOSE)
                {
                    m_lstTitle[i] = (int)TITLE_TYPE.TT_NONE;
                }
            }
        }
        
        // 
        private List<int> m_lstTitle = new List<int>();
        private int m_nMaxX = (int)MAPSIZE.MAPSIZE_X;
        private int m_nMaxY = (int)MAPSIZE.MAPSIZE_Y;
    }

}